package a10_动态规划;

/**
 * <p>
 * a03_爬楼梯复习1
 * </p>
 *
 * @author flyduck
 * @since 2025/1/21
 */
public class a03_爬楼梯复习1 {
    //dp[i]含义：到达第i个台阶有dp[i]种方式
    //递推公式：dp[i] = dp[i-1] + dp[i-2]
    //初始化：dp[0] = 0 dp[1] = 1 dp[2] = 2
    public int climbStairs(int n) {
        if (n <= 2) {
            return n;
        }
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;
        dp[2] = 2;
        for (int i = 3; i < dp.length; i++) {
            dp[i] = dp[i-1] + dp[i-2];
        }
        return dp[n];
    }
}
